﻿using System;

namespace MaximumSumOfK
{
    class MaximumSumOfK
    {
        static void PrintResult(int[] result)
        {
            Console.Write("{ ");
            for (int index = 0, length = result.Length - 1; index < length; index++)
            {
                Console.Write("{0}, ", result[index]);
            }
            Console.WriteLine("{0} }}", result[result.Length - 1]);
        }
        static int[] MaxSumSequenceOfK(int[] numbers, int k)
        {
            int maxSum = int.MinValue,
                startIndex = 0;
            int[] result;
            for (int index = 0, length = numbers.Length - k; index <= length; index++)
            {
                int tmpSum = 0;
                for (int secondIndex = index, toLength = index + k; secondIndex < toLength; secondIndex++)
                {
                    tmpSum += numbers[secondIndex];
                }
                if (tmpSum > maxSum)
                {
                    maxSum = tmpSum;
                    startIndex = index;
                }
            }
            result = new int[k];
            Array.Copy(numbers, startIndex, result, 0, k);
            return result;
        }
        static void Main(string[] args)
        {
            int arrayLength;
            int numberOfElements;
            int[] numbers;
            int[] result;

            Console.Write("Please enter the length of your array: ");
            arrayLength = int.Parse(Console.ReadLine());
            Console.Write("Please enter an integer for K less than or equal to {0}: ", arrayLength);
            numberOfElements = int.Parse(Console.ReadLine());
            if (numberOfElements > arrayLength)
            {
                numberOfElements = arrayLength;
            }
            numbers = new int[arrayLength];
            for (int index = 0; index < arrayLength; index++)
            {
                Console.Write("Index [{0}]: ", index);
                numbers[index] = int.Parse(Console.ReadLine());
            }
            result = MaxSumSequenceOfK(numbers, numberOfElements);
            PrintResult(result);
        }
    }
}
